#include "point.h"
#include <cmath>

point::point() : x(0), y(0), z(0)
{
}

inline point::point(double x,double y,double z): x(x), y(y), z(z)
{
}

inline point point::cylindre(double r,double phi, double h)
{
    return point(r*cos(phi),r*sin(phi),h);
}

inline point point::polaire(double r,double phi,double teta)
{
    return point(r*cos(teta)*sin(phi) ,r*sin(teta)*sin(phi)  ,r*cos(teta));
}

point& point::operator= (const point& p)
{
    x=p.x;
    y=p.y;
    z=p.z;
    return *this;
}

point point::operator+ (const point& p) const
{
    point ret;
    ret.x=this->x+p.x;
    ret.y=this->y+p.y;
    ret.z=this->z+p.z;
    return ret;
}

point point::operator- (const point& p) const
{
    point ret;
    ret.x=this->x-p.x;
    ret.y=this->y-p.y;
    ret.z=this->z-p.z;
    return ret;
}

point& point::operator+=(const double& t)
{
    x+=t;
    y+=t;
    z+=t;
    return *this;
}

point& point::operator+=(const point& p)
{
    x+=p.x;
    y+=p.y;
    z+=p.z;
    return *this;
}


point& point::operator-=(const double& t)
{
    x-=t;
    y-=t;
    z-=t;
    return *this;
}

point& point::operator-=(const point& p)
{
    x-=p.x;
    y-=p.y;
    z-=p.z;
    return *this;
}

point& point::operator*=(const point& p)
{
    x*=p.x;
    y*=p.y;
    z*=p.z;
    return *this;
}

point& point::operator*=(const double& t)
{
    this->x=double(t)*this->x;
    this->y=double(t)*this->y;
    this->z=double(t)*this->z;
    return *this;
}

point point::operator^ (const point& p) const
{
    point ret;
    ret.x=y*p.z - z*p.y;
    ret.y=z*p.x - x*p.z;
    ret.z=x*p.y - y*p.x;
    return ret;
}

point& point::translation(double x,double y,double z)
{
	this->x+=x;
	this->y+=y;
	this->z+=z;
    return *this;
}

point& point::rotation(double xaxe,double yaxe,double zaxe,double angle)
{
	point p(xaxe,yaxe,zaxe);
	point &encours=*this;
	encours=encours*cos(angle)+p*(encours*p)*(1-cos(angle))+(encours^p)*sin(angle);
	return encours;
}


point point::operator+ (const double& t) const
{
	point ret(*this);
	ret+=t;
	return ret;
}

point point::operator- (const double& t) const
{
	point ret(*this);
	ret-=t;
	return ret;
}

point point::operator* (const double& t) const
{
	point ret(*this);
	ret*=t;
	return ret;
}

point& point::Setx(double x)
{
	this->x=x;
	return *this;
}

point& point::Sety(double y)
{
	this->y=y;
	return *this;
}

point& point::Setz(double z)
{
	this->z=z;
	return *this;
}

double point::Getphi() const
{
	return atan2(x,y);
}

double point::Geteta() const
{
	return atan2(z,sqrt(x*x+y*y));
}